package traitClass

/**
  * Human
  *
  * @author zhangyimin
  * @date 2018-09-17 下午2:35
  * @version 1.0
  */
trait Human {

  //抽象字段,这个字段只有get方法
  val id: Int
  //抽象字段,这个字段有get和set方法
  var name: String

  def sayHello: String = "Hello " + name

}

trait Action {
  //抽象方法
  def getActionName(): String
}


class Student(override val id: Int, override var name: String) extends Human with Action {
  //实现Action中的方法
  override def getActionName: String = "play football"

  //实现重写Human中的方法
  override def sayHello: String = super.sayHello
}


object TestTait {
  def main(args: Array[String]): Unit = {
    //    val s1:Human with Action=new Student(10086,"Tom")
    val s1 =new Student(10086, "Tom")
    println(s1.sayHello)
    println(s1.getActionName)
  }
}

